[ENG-551] Replace all other usages of GovtOrgSelector with the new picker#16451
Conversation
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
WalkthroughThis PR replaces the deprecated ChangesGovtOrganizationPicker Migration
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying care-preview with
|
| Latest commit: |
273ca03
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://653dcacc.care-preview-a7w.pages.dev |
| Branch Preview URL: | https://eng-551-replace-all-other-us.care-preview-a7w.pages.dev |
There was a problem hiding this comment.
Pull request overview
This PR migrates remaining form flows away from the deprecated GovtOrganizationSelector to the newer GovtOrganizationPicker, and removes the old selector implementation from the codebase.
Changes:
- Replaced
GovtOrganizationSelectorusages withGovtOrganizationPickerin public patient registration, user form, and facility form. - Updated these forms to manage the picker’s selected
Organizationobject via local component state. - Deleted the deprecated
GovtOrganizationSelectorcomponent file.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/pages/PublicAppointments/PatientRegistration.tsx | Swaps the geo organization field to use GovtOrganizationPicker for public patient registration. |
| src/pages/Organization/components/GovtOrganizationSelector.tsx | Removes the deprecated selector component implementation. |
| src/components/Users/UserForm.tsx | Updates geo organization selection to use GovtOrganizationPicker with Organization state. |
| src/components/Facility/FacilityForm.tsx | Updates geo organization selection to use GovtOrganizationPicker and new state wiring. |
Comments suppressed due to low confidence (1)
src/components/Facility/FacilityForm.tsx:205
- On edit,
facilityData.geo_organization.idis always written into the form viaform.reset, even if the loaded organization has children. WithGovtOrganizationPicker, the UI can show a parent organization while the RHF field stays non-empty, so zod validation passes and the form can submit an intermediate geo org. Consider resettinggeo_organizationto "" unless the selected org is a leaf (and keepselectedGeoOrgset so the cascade remains visible).
useEffect(() => {
if (facilityData) {
setSelectedGeoOrg(facilityData.geo_organization);
form.reset({
facility_type: facilityData.facility_type,
name: facilityData.name,
description: facilityData.description || "",
features: facilityData.features || [],
pincode: facilityData.pincode || undefined,
geo_organization: facilityData.geo_organization.id,
address: facilityData.address,
Greptile SummaryThis PR replaces the deprecated
Confidence Score: 4/5Safe to merge after fixing the two onChange handlers in FacilityForm and UserForm, and the missing form.setValue call in UserForm's org-context effect. FacilityForm and UserForm both allow an intermediate (non-leaf) org to pass form validation and reach the API, which was explicitly blocked by the old component's required prop. UserForm also silently drops the pre-filled geo org on first submit when the user is creating from a govt org context. src/components/Users/UserForm.tsx and src/components/Facility/FacilityForm.tsx Important Files Changed
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/Facility/FacilityForm.tsx`:
- Around line 105-107: The useEffect that sets selectedGeoOrg from the bootstrap
org is overwriting edit-mode state; update the effect in FacilityForm (the
useEffect that calls setSelectedGeoOrg with org/org_type) to only apply when the
form is not in edit-mode or when there is no existing selectedGeoOrg from the
entity backing the form (e.g., guard on an isEditMode flag or on the absence of
a preloaded selectedGeoOrg value), so that the bootstrap org does not replace
user/entity-backed selectedGeoOrg; keep references to org, organizationId,
selectedGeoOrg, and setSelectedGeoOrg when implementing this guard.
In `@src/components/Users/UserForm.tsx`:
- Around line 806-810: The onChange handler for the organization picker
currently writes whatever node ID is selected into geo_organization; change it
to persist only leaf organization IDs by checking the selected organization's
isLeaf (or equivalent) property or using a helper to get the leafId before
calling setSelectedGeoOrg and form.setValue; update the onChange in the
component that sets setSelectedGeoOrg and calls
form.setValue("geo_organization", ...) to pass the leaf id (or empty string when
a non-leaf is selected) so geo_organization mirrors the leaf-only behavior used
in other migrated forms.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: c09d6a95-87c4-44d9-9a3c-69b4604166f8
📒 Files selected for processing (4)
src/components/Facility/FacilityForm.tsxsrc/components/Users/UserForm.tsxsrc/pages/Organization/components/GovtOrganizationSelector.tsxsrc/pages/PublicAppointments/PatientRegistration.tsx
💤 Files with no reviewable changes (1)
- src/pages/Organization/components/GovtOrganizationSelector.tsx
🎭 Playwright Test ResultsStatus: ❌ Failed
📊 Detailed results are available in the playwright-final-report artifact. Run: #9563 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/Facility/FacilityForm.tsx`:
- Around line 105-115: The effect in FacilityForm that sets selectedGeoOrg and
calls form.setValue("geo_organization") is overwriting edit-mode selections when
the parent org query resolves; guard the useEffect (the effect that depends on
org, organizationId, form) with an edit-mode check (e.g., only run when not
editing: !facilityId) so it skips setting selectedGeoOrg and form.setValue
during edits, preserving the entity-backed geo_organization value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: f0425b4f-0aa8-493a-86dd-cfe8071d1252
📒 Files selected for processing (3)
src/components/Facility/FacilityForm.tsxsrc/components/Users/UserForm.tsxsrc/hooks/useGovtOrganizationLevel.ts
💤 Files with no reviewable changes (1)
- src/hooks/useGovtOrganizationLevel.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/Users/UserForm.tsx`:
- Around line 804-810: The selectedGeoOrg picker value shown in the component
(line 805) is not being synced into the form state when it is programmatically
set during the create flow. While the onChange handler in lines 808-810 updates
the form field when the user manually interacts with the picker, there is no
mechanism to sync the preselected value into the form's geo_organization field
when selectedGeoOrg is initially populated by the org bootstrap effect. Add an
effect that watches selectedGeoOrg and updates the form's geo_organization field
via form.setValue whenever selectedGeoOrg changes, ensuring the form state stays
in sync with the picker's displayed value during create mode.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d6bb76e1-e4b5-4bc5-b9a5-83cfd92b0fa9
📒 Files selected for processing (2)
src/components/Facility/FacilityForm.tsxsrc/components/Users/UserForm.tsx
| requiredDepth={1} | ||
| value={selectedGeoOrg} | ||
| onChange={(organization) => { | ||
| setSelectedGeoOrg(organization); | ||
| form.setValue("geo_organization", organization?.id ?? "", { | ||
| shouldDirty: true, | ||
| }) | ||
| } | ||
| required={false} | ||
| }); |
There was a problem hiding this comment.
Sync preselected picker value into the form state in create mode.
Line 805 renders selectedGeoOrg as selected, but Lines 808-810 update geo_organization only after user interaction. In create flow, the org bootstrap effect can prefill the picker while data.geo_organization stays empty on submit.
Suggested fix
useEffect(() => {
- setSelectedGeoOrg(org && org.org_type === "govt" ? org : null);
-}, [org, organizationId]);
+ const govtOrg = org && org.org_type === "govt" ? org : null;
+ setSelectedGeoOrg(govtOrg);
+ if (!isEditMode) {
+ form.setValue("geo_organization", govtOrg?.id ?? "", {
+ shouldDirty: false,
+ });
+ }
+}, [org, isEditMode, form]);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/components/Users/UserForm.tsx` around lines 804 - 810, The selectedGeoOrg
picker value shown in the component (line 805) is not being synced into the form
state when it is programmatically set during the create flow. While the onChange
handler in lines 808-810 updates the form field when the user manually interacts
with the picker, there is no mechanism to sync the preselected value into the
form's geo_organization field when selectedGeoOrg is initially populated by the
org bootstrap effect. Add an effect that watches selectedGeoOrg and updates the
form's geo_organization field via form.setValue whenever selectedGeoOrg changes,
ensuring the form state stays in sync with the picker's displayed value during
create mode.


Proposed Changes
GovtOrganizationSelectorwithGovtOrganizationPickerSummary by CodeRabbit
geo_organizationfield synchronized on create and edit.